<?php
include("../db_connect.php");
include("../class/objName.php");
?>

<script>
var pf	= new String();
var pl	= new String();
var pe 	= new String();
var pt 	= new String();
var tx 	= new String();
var deliver = new String();

$(document).ready(function(){
$("#buyed_reserve_item_data").load("admin/buyed_reserve_item_data.php");
var pfname 	= $("#paypal_Fname");
var plname 	= $("#paypal_Lname");
var pemail 	= $("#paypal_email");
var ptype 	= $("#payment_type");
var txn_id	= $("#txn_id");
var delivery = $("#selectdelivered");

	$("#paypal_Fname").keydown(function (){
	pf = trim($(this).val());
	pl = plname.val();
	pe = pemail.val();
	pt = ptype.val();
	tx = txn_id.val();
	deliver = delivery.val();
	
	$("#buyed_reserve_item_data").html(loader).load("admin/buyed_reserve_item_data.php?fname="+pf+"&lname="+pl+"&email="+pe+"&ptype="+pt+"&txn_id="+tx+"&delivered="+deliver);
	
		
	});
	$("#paypal_Lname").keydown(function (){
		pf = trim(pfname.val());
		pl = trim($(this).val());
		pe = pemail.val();
		pt = ptype.val();
		tx = txn_id.val();
		deliver = delivery.val();
	
	$("#buyed_reserve_item_data").html(loader).load("admin/buyed_reserve_item_data.php?fname="+pf+"&lname="+pl+"&email="+pe+"&ptype="+pt+"&txn_id="+tx+"&delivered="+deliver);
	});
	
	$("#paypal_email").keydown(function (){
		pf = trim(pfname.val());
		pl = plname.val();
		pe = trim($(this).val());
		pt = ptype.val();
		tx = txn_id.val();
		deliver = delivery.val();
		
	$("#buyed_reserve_item_data").html(loader).load("admin/buyed_reserve_item_data.php?fname="+pf+"&lname="+pl+"&email="+pe+"&ptype="+pt+"&txn_id="+tx+"&delivered="+deliver);
	
	
	});
	$("#payment_type").change(function (){
		pf = trim(pfname.val());
		pl = plname.val();
		pe = pemail.val();
		pt = ptype.val();
		tx = txn_id.val();
		deliver = delivery.val();
		
		if( pt==""){  pt= "all"}
		$("#buyed_reserve_item_data").html(loader).load("admin/buyed_reserve_item_data.php?fname="+pf+"&lname="+pl+"&email="+pe+"&ptype="+pt+"&txn_id="+tx);
	
	});
	
	$("#txn_id").keydown(function (){
		pf = trim(pfname.val());
		pl = plname.val();
		pe = pemail.val();
		pt = ptype.val();
		tx = txn_id.val();
		deliver = delivery.val();
		
		$("#buyed_reserve_item_data").html(loader).load("admin/buyed_reserve_item_data.php?fname="+pf+"&lname="+pl+"&email="+pe+"&ptype="+pt+"&txn_id="+tx+"&delivered="+deliver);
		
	
	});
	
	$("#selectdelivered").change(function (){
		pf = trim(pfname.val());
		pl = plname.val();
		pe = pemail.val();
		pt = ptype.val();
		tx = txn_id.val();
		deliver = $(this).val();
		
		$("#buyed_reserve_item_data").html(loader).load("admin/buyed_reserve_item_data.php?fname="+pf+"&lname="+pl+"&email="+pe+"&ptype="+pt+"&txn_id="+tx+"&delivered="+deliver);
		
	
	});
	
	$("#buyed_report").click(function (){
		pf = trim(pfname.val());
		pl = trim(plname.val());
		pe = pemail.val();
		pt = ptype.val();
		tx = txn_id.val();
		deliver = delivery.val();
		window.open("reports/buyed_report.php?fname="+pf+"&lname="+pl+"&email="+pe+"&ptype="+pt+"&txn_id="+tx+"&delivered="+deliver);
	});
	
	
	
	
	$("#deliveredapp").click(function(){

	var buyeditem = new Array();
	$(".buyed_reserve_item_data tr td").find("input:checked").each(function(e){
			buyeditem[e] = $(this).val();
		});
	
		if (buyeditem.length <=0){
				$("#msgbox").empty().html("no row selected");
				$("#msgbox").dialog({
					modal:true,
					title:"Error",
					width:350,
					height: 200,
					show: "fade",
					hide: "fade",
					buttons: {
						OK: function() {
							$( this ).dialog( "close" );
						}

					},
				});
				
				

		}
		else if(buyeditem.length >=1){
		
		$("#msgbox").empty().html("Confirm delivery?");
			$("#msgbox").dialog({
				modal:true,
				width:350,
				height: 200,
				show:"fade",
				hide: "fade",
				buttons: {
					OK: function() {
						$( this ).dialog( "close" );
						isdelivered(buyeditem);
					},
					CANCEL: function() {
						$( this ).dialog( "close" );
					}
				},

			});
			

		}

});//end of approve.click()
	
});//end of document ready


function isdelivered(item){
	$.ajax({
		url:"admin/deliverapprove.php?id="+item,
		success:function(data){
		$("#buyed_reserve_item_data").html(loader).load("admin/buyed_reserve_item_data.php");
		}
	})

}



function trim(data){
	var a = new Array();
	a = data.split(" ");
	var x = a.length;
	
	if(x>1){
		
		return a;
	}
	else{
		
		return data;
	}
	
	
}


checked = false;		  
function allbuyed(){
	if (checked == false){
		checked = true
	}
	else{
	checked = false
	}
	for (var i = 0; i < document.getElementById('delivered').elements.length; i++){
		document.getElementById('delivered').elements[i].checked = checked;
	}	
}
</script>
<div>
		<div class="headersearch">
			<label>Paypal First Name:</label>
			<input type="text" id="paypal_Fname" placeholder="First Name"/>
			<label>Paypal Last Name</label>
			<input type="text" id="paypal_Lname"/ placeholder="Last Name">
		</div>
		
		<div class="headersearch ">
		<label>Paypal Email:</label>
		<input type="text" id="paypal_email" placeholder="Email"/>
		<label>Txn Id</label>
		<input type="text" id="txn_id" placeholder="Email"/>
		
			<label>Delivered:</label>
			<select id="selectdelivered" >
				<option value="">Select All</option>
				<option value="yes">Yes</option>
				<option value="no">No</option>
			</select>
		
		<label>Delivered:</label><button id="deliveredapp">Yes</button>
		<button id="buyed_report">Create a Report</button>
		</div>
	</div>
	<div style="overflow:auto">
		<div id="buyed_reserve_item_data" style="width:920px;"></div>
	</div>

